import 'package:manager/models/page_model.dart';

import 'entity_factory.dart';

///解析List<T> 类型的数据
class BasePageEntity<T> {
  int code;
  String msg;
  PageModel<T> data;

  bool get isSuccess {
    return code == 0;
  }

  List<T> get records=> data.records;

  BasePageEntity({required this.code, required this.msg, required this.data});

  factory BasePageEntity.fromJson(json) {
    if (json == null || json.isEmpty) {
      return BasePageEntity(
          code: -1, msg: '无响应数据', data: PageModel(records: []));
    }
    return BasePageEntity(
        code: json['code'] ?? -1,
        msg: json['msg'] ?? '无响应数据',
        data: PageModel<T>.fromJson(json['data']));
  }
}
